/*******************************************************************************

 * Copyright 2011 See AUTHORS file.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package com.badlogicgames.superjumper;

import java.util.Random;

import com.badlogic.gdx.Gdx;

public class Squirrel extends DynamicGameObject {
    public static final float SQUIRREL_WIDTH = 1;
    public static final float SQUIRREL_HEIGHT = 0.6f;
    public static final float SQUIRREL_VELOCITY = 2f;
    private Pigeon pigeon;
    private Random rand =  new Random();
    
    float stateTime = 0;
    
    public Squirrel(float x, float y, Pigeon p) {
        super(x, y, SQUIRREL_WIDTH, SQUIRREL_HEIGHT);
        velocity.set(SQUIRREL_VELOCITY*rand.nextFloat()+1, SQUIRREL_VELOCITY*rand.nextFloat()+1 );
        this.pigeon = p;
    }
    
    public void update(float deltaTime) {
       // position.add(velocity.x * deltaTime, velocity.y * deltaTime);
        bounds.x = position.x - SQUIRREL_WIDTH / 2;
        bounds.y = position.y - SQUIRREL_HEIGHT / 2;
        float d = this.position.dst(this.pigeon.position);
        Gdx.app.log("squirrel position", this.position + "");
        Gdx.app.log("pigeon position", pigeon.position + "");
        Gdx.app.log("distance", d + "");
       
        if(d < 5){
        	position.add((this.pigeon.position.x - this.position.x)/velocity.x*deltaTime, 
  			      (this.pigeon.position.y - this.position.y)/velocity.y*deltaTime);
        }
        
        stateTime += deltaTime;
    }
}
